<%@ page contentType="text/html; charset=UTF-8" language="java"
	import="java.util.*,org.yoao.crm.acl.ACLTool,org.yoao.crm.bean.CustomerType,org.yoao.crm.page.framework.IViewPageService,org.yoao.crm.page.framework.ViewPageHelper,org.yoao.crm.bean.Customer"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";

	org.yoao.crm.bean.Session userSession = (org.yoao.crm.bean.Session) session
			.getAttribute("userSession");
	String actionPermission = userSession.getActionPermission();

	IViewPageService customerPage = (IViewPageService) session
			.getAttribute(ViewPageHelper.SESSION_PAGE);

	List list = (List) request.getAttribute("CUSTOMERLIST");
	List typeList = (List) request.getAttribute("CUSTOMERTYPE");

	String searchCustomerId = (String) request
			.getAttribute("searchCustomerId");
	if (searchCustomerId == null)
		searchCustomerId = "";
	String searchCustomerName = (String) request
			.getAttribute("searchCustomerName");
	if (searchCustomerName == null)
		searchCustomerName = "";
	String searchCompanyName = (String) request
			.getAttribute("searchCompanyName");
	if (searchCompanyName == null)
		searchCompanyName = "";
	String searchProvince = (String) request
			.getAttribute("searchProvince");
	if (searchProvince == null)
		searchProvince = "";
	String searchCity = (String) request.getAttribute("searchCity");
	if (searchCity == null)
		searchCity = "";
	String searchState = (String) request.getAttribute("searchState");
	if (searchState == null)
		searchState = "";
	String searchMobile = (String) request.getAttribute("searchMobile");
	if (searchMobile == null)
		searchMobile = "";
	String searchSignature = (String) request
			.getAttribute("searchSignature");
	if (searchSignature == null)
		searchSignature = "";
	String searchUserName = (String) request
			.getAttribute("searchUserName");
	if (searchUserName == null)
		searchUserName = "";
	String searchUserSno = (String) request
			.getAttribute("searchUserSno");
	if (searchUserSno == null)
		searchUserSno = "";
%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>CRM-客户列表</title>
		<jsp:include page="../public/publicJs.jsp" flush="false"></jsp:include>
		<script type="text/javascript">
var preTr = null;
var preColor = "";
function changeTrColor() {
	try {
		var tag = event.srcElement;
		while (tag.tagName != "TR")
			tag = tag.parentElement;
		switch (event.type) {
		case "mouseover":
			preColor = tag.currentStyle.backgroundColor;
			if (tag.currentStyle.highLightColor)
				tag.style.background = tag.currentStyle.highLightColor;
			else
				tag.style.background = "#FFFF00";
			break;
		case "mouseout":
			if (preTr != tag)
				tag.style.background = preColor;
			break;
		}
	} catch (E) {
	}
}
function openUser(id) {
	var user = window.showModalDialog(
			"<%=basePath%>kmjsp/dialog/datawindowUser.jsp", "用户选择",
			"dialogWidth=300px;dialogHeight=380px");
	if ("CANCELUSER" == user)
		return;
	if (user == "")
		user = "|";
	if (!user)
		return;

	var sarray = user.split("|");
	if (sarray != null) {
		if (id) {
			if (!id || id == "") {
				alert("未获取到报名人ID,数据未同步到客户中心!");
				return;
			}
			var vUrl = "<%=basePath%>customer.crm?method=distribution&id=" + id
					+ "&sno=" + sarray[0];
			var result = ajax_getReturnText(vUrl);
			if (result.indexOf("[SUCCESS]") > -1) {
				location.reload();
			} else
				alert(result);
		} else {
			var objSno = document.all.searchUserSno;
			for ( var i = 0; i < objSno.length; i++) {
				objSno[i].value = sarray[0];
			}

			var objName = document.all.searchUserName;
			for ( var i = 0; i < objName.length; i++) {
				objName[i].value = sarray[1];
			}
		}
	}
}
</script>
	</head>

	<body topmargin="0" leftmargin="0"
		onLoad="setDivHeight('divList', -160);">
		<div id="div_load"
			style='display: block; background: #FFFFFF; width: 240px; height: 12px; margin-top: -120px; margin-left: -200px; left: 50%; top: 50%; position: absolute; padding: 5px 5px 5px 5px; z-index: 1'>
			<img src="<%=basePath%>images/loading.gif" class="icon1"
				align="absmiddle" />
			数据加载中,请稍后...
		</div>
		<table class="maintab_content_table" border="0" width="100%"
			cellspacing="0" cellpadding="0" height="25">
			<tr class="tree_title_txt">
				<td nowrap width="100%" class="tree_title_txt" valign="middle"
					id="cwCellTopTitTxt">
					<font color="#154288">客户列表 </font>
				</td>
			</tr>
		</table>

		<div id="ds"
			style="display: none; background: #EBEBEB; width: 100px; height: 20px; left: 50%; top: 50%; position: absolute; padding: 5px 5px 5px 5px; z-index: 1">
			<font color="#FF0000"><img
					src="<%=basePath%>images/loading.gif" alt="数据加载中" align="absmiddle" />数据加载中...</font>
		</div>
		<div style="width: 100%;">
			<fieldset
				style="width: 100%; TEXT-ALIGN: center; margin: 0px 5px 0px 5px;">
				<legend>
					&nbsp;搜索
					<img name="Changeicon" border="0"
						src="<%=basePath%>images/jt_b.gif"
						onClick="javascript:fieldsetHidden();" style="cursor: hand"
						title="显示/隐藏内容">
					&nbsp;
				</legend>
				<form name="searchForm"
					action="<%=basePath%>customer.crm?method=sms" method="post">
					<center>
						<table border="0" width="100%" cellspacing="5" cellpadding="0">
							<tr>
								<td nowrap>
									客户码:
								</td>
								<td>
									<input name="searchCustomerId" accesskey="s" type="text"
										class="text_220" style="width: 150px" size="25"
										value="<%=searchCustomerId%>">
								</td>
								<td nowrap>
									客户名称:
								</td>
								<td>
									<input name="searchCustomerName" accesskey="s" type="text"
										class="text_220" style="width: 150px" size="25"
										value="<%=searchCustomerName%>">
								</td>
								<td nowrap>
									公司名称:
								</td>
								<td>
									<input name="searchCompanyName" accesskey="s" type="text"
										class="text_220" style="width: 150px" size="25"
										value="<%=searchCompanyName%>">
								</td>
								<td style=""></td>
							</tr>
							<tr>
								<td nowrap>
									省份:
								</td>
								<td>
									<input name="searchProvince" accesskey="s" type="text"
										class="text_220" style="width: 150px" size="25"
										value="<%=searchProvince%>">
								</td>
								<td nowrap>
									是否签到:
								</td>
								<td>
									<select name="searchSignature" class="text_220"
										style="width: 150px;">
										<option value="">
											<option value="1" <%if ("1".equals(searchSignature)) {%>
												selected <%}%>>
												已签到
												<option value="0" <%if ("0".equals(searchSignature)) {%>
													selected <%}%>>
													未签到
									</select>
								</td>
								<td nowrap>
									客户类别:
								</td>
								<td>
									<select name="searchState" style="width: 150px;">
										<option value="">
											<%
												if (typeList != null && !typeList.isEmpty()) {
													for (int i = 0; i < typeList.size(); i++) {
														CustomerType customerType = (CustomerType) typeList.get(i);
											%>
											<option value="<%=customerType.getTypeCode()%>"
												<%if (customerType.getTypeCode().equals(searchState)) {%>
												selected <%}%> /><%=customerType.getTypeName()%>
												<%
													}
													}
												%>

									</select>
								</td>
								<td style=""></td>
							</tr>
							<tr>
								<td nowrap>
									城市:
								</td>
								<td>
									<input name="searchCity" accesskey="s" type="text"
										class="text_220" style="width: 150px" size="25"
										value="<%=searchCity%>">
								</td>
								<td class="Form_BBS_Lable" valign="middle">
									联系电话
								</td>
								<td>
									<input name="searchMobile" style="width: 150px"
										class="text_220" type="text" size="25"
										value="<%=searchMobile%>">
								</td>
								<td nowrap>
									服务人员:
								</td>
								<td>
									<input name="searchUserName" value="<%=searchUserName%>"
										type="text" style="width: 125px" class="text_220" size="15"
										readonly>
									<input name="searchUserSno" type="hidden"
										value="<%=searchUserSno%>">
									<img src="<%=basePath%>images/sbtn_more.gif" alt="用户选择"
										onclick="openUser();" width="19" height="19" align="absmiddle"
										style="cursor: pointer" />

								</td>
								<td style="">
									<input name="image" type="image"
										src="<%=basePath%>images/tbtn_searh.gif" alt="查询"
										align="absmiddle" onclick="searchForm.submit();">
								</td>
							</tr>
						</table>
					</center>
				</form>
			</fieldset>
		</div>

		<form action="<%=basePath%>customer.crm?method=sms" name="viewForm"
			method="post">
			<input name="searchCustomerId" type="hidden"
				value="<%=searchCustomerId%>">
			<input name="searchCustomerName" type="hidden"
				value="<%=searchCustomerName%>">
			<input name="searchCompanyName" type="hidden"
				value="<%=searchCompanyName%>">
			<input name="searchCity" type="hidden" value="<%=searchCity%>">
			<input name="searchProvince" type="hidden"
				value="<%=searchProvince%>">
			<input name="searchState" type="hidden" value="<%=searchState%>">
			<input name="searchMobile" type="hidden" value="<%=searchMobile%>">
			<input name="searchSignature" type="hidden"
				value="<%=searchSignature%>">
			<input name="searchUserName" type="hidden"
				value="<%=searchUserName%>">
			<input name="searchUserSno" type="hidden" value="<%=searchUserSno%>">
			<table border="0" width="100%" height="25" cellspacing="0"
				cellpadding="0">
				<tr class="maintab">
					<td width="1%" align="center" valign="middle" id="cwCellTopTitTxt">
						&nbsp;
						<input type="checkbox" onClick="selectAction('itemselect')"
							value="1" />
					</td>
					<%
						if (ACLTool.isSms(actionPermission)) {
					%>
					<td width="2%">
						<a href="#" accesskey="n"
							onClick="dataHander('sms','<%=basePath%>sms.crm?method=send&id=', viewForm.itemselect);"><img
								align="absmiddle" src="<%=basePath%>images/sbtn_sel.gif"
								alt="发送短信(Alt+S)" align="absmiddle"> </a>
					</td>
					<%
						}
					%>
					<td width="2%"></td>
					<td width="2%"></td>

					<td nowrap width="68%" align="right">
						<input id="<%=ViewPageHelper.PAGE_ACTION%>"
							name="<%=ViewPageHelper.PAGE_ACTION%>" type="hidden" value="" />
						共
						<%=customerPage.getTotalRows()%>条 /
						<%=customerPage.getPageCount()%>
						页
						<%
							if (customerPage.getPageIndex() > 1) {
						%>
						<img align="absmiddle" style="cursor: pointer;"
							onClick="goPage('FIRST_PAGE')"
							src="<%=basePath%>images/ico_first.gif" alt="首页" border="0" />
						<img align="absmiddle" style="cursor: pointer;"
							onClick="goPage('PREVIOUS_PAGE')"
							src="<%=basePath%>images/ico_prev.gif" alt="上一页" border="0" />
						<%
							} else {
						%>
						<img align="absmiddle" style="filter: Gray;"
							src="<%=basePath%>images/ico_first.gif" alt="首页" border="0" />
						<img align="absmiddle" style="filter: Gray;"
							src="<%=basePath%>images/ico_prev.gif" alt="上一页" border="0" />
						<%
							}
						%>
						第
						<font color="red"><%=customerPage.getPageIndex()%></font> 页
						<%
							if (customerPage.getPageIndex() < customerPage.getPageCount()) {
						%>
						<img align="absmiddle" style="cursor: pointer;"
							onClick="goPage('NEXT_PAGE')"
							src="<%=basePath%>images/ico_next.gif" alt="下一页" border="0" />
						<img align="absmiddle" style="cursor: pointer;"
							onClick="goPage('LAST_PAGE')"
							src="<%=basePath%>images/ico_last.gif" alt="尾页" border="0/">
						<%
							} else {
						%>
						<img align="absmiddle" style="filter: Gray;"
							src="<%=basePath%>images/ico_next.gif" alt="下一页" border="0" />
						<img align="absmiddle" style="filter: Gray;"
							src="<%=basePath%>images/ico_last.gif" alt="尾页" border="0" />
						<%
							}
						%>
					</td>
					<td nowrap width="1%">
						<img align="absmiddle" src="<%=basePath%>images/sbtn_split.gif" />
					</td>
					<td nowrap width="8%">
						转到&nbsp;
						<input id="<%=ViewPageHelper.PAGE_NO%>"
							name="<%=ViewPageHelper.PAGE_NO%>" type="text" size="2"
							value="<%=customerPage.getPageIndex()%>"
							onKeyPress="javascript:if(event.keyCode == 13){goPage('jump');}" />
						&nbsp;页
						<img align="absmiddle" style="cursor: pointer;"
							onClick="goPage('jump')" src="<%=basePath%>images/goto.gif"
							alt="执行" border="0" align="absmiddle">
					</td>
				</tr>
			</table>

			<div id="divList"
				style="vertical-align: top; width: 100%; overflow: auto;">
				<table border="0" style="border-collapse: collapse;" align="center"
					cellpadding="0" cellspacing="0" width="100%"
					class="maintab_content_table">
					<tr class="maintab_content_table_title">
						<th width="1%"></th>
						<th align="center" nowrap>
							客户码
						</th>
						<th align="center" nowrap>
							联系人
						</th>
						<th align="center" nowrap>
							公司名称
						</th>
						<th align="center" nowrap>
							省份
						</th>
						<th align="center" nowrap>
							城市
						</th>
						<th align="center" nowrap>
							手机
						</th>
						<th align="center" nowrap>
							客户类别
						</th>
						<th align="center" nowrap>
							服务人员
						</th>
					</tr>
					<%
						if (list != null) {
							int size = list.size();
							for (int i = 0; i < size; i++) {
								Customer customer = (Customer) list.get(i);
					%>
					<tr onMouseOver="changeTrColor()" onMouseOut="changeTrColor()"
						title="<%=customer.getCustomerName()%>">
						<td nowrap align="center">
							<input class="rd" type="checkbox" name="itemselect"
								value="<%=customer.getId()%>" />
						</td>
						<td nowrap><%=customer.getCustomerId()%></td>
						<td nowrap><%=customer.getCustomerName()%></td>
						<td nowrap><%=customer.getCompanyName()%></td>
						<td nowrap><%=customer.getProvince()%></td>
						<td nowrap><%=customer.getCity()%></td>
						<td nowrap><%=customer.getMobile()%></td>
						<td nowrap><%=customer.getState()%></td>
						<td nowrap><%=customer.getUserSno()%></td>
					</tr>
					<%
						}
						}
					%>
				</table>
			</div>
		</form>
	</body>
</html>
<script>
document.getElementById("div_load").style.display = "none";</script>